﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2011/12/28
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Luminji.Exam.Model.Subjects;

namespace Luminji.ExamWeb.Helpers.Tools
{
    public class SubjectTool
    {
        public static string GetSubjectHtmlView(IList<Subject> subjects)
        {
            if (subjects == null)
            {
                return "";
            }
            re = string.Empty;
            RecusiveSubject(subjects);
            return re.Substring(4, re.Length - 11);
        }

        static string re;

        static void RecusiveSubject(IList<Subject> subjects)
        {
            if (subjects == null)
            {
                return;
            }
            re += @"<ul>" + Environment.NewLine;
            foreach (var item in subjects)
            {
                re += @"<li><a href='subject.html?subject=" + item.SubjectName + "&code=" + item.SubjectCode + "'>" + item.SubjectName + "</a>" + Environment.NewLine;
                if (item.Children != null && item.Children.Count > 0)
                {
                    RecusiveSubject(item.Children);
                }
                re += "</li>" + Environment.NewLine;
            }
            re += @"</ul>" + Environment.NewLine;
        }
    }
}